#/bin/bash

:<<description
功能：打包中介
描述：bundle 转 aundle/zundle等

description


#设置脚本异常立即退出
set -e
if [[ ${debug} == 'T' ]]; then set -x; fi
#获取当前脚本名
script=$0
scriptDir=$(cd $(dirname $0); pwd)
#导入通用函数
for file in $(ls ${workDir}/function*.sh); do source ${file}; done
#获取输入参数并命名
action=$1
targetResource=$2
sequence=$3
executeProfile=$4
host=$5
user=$6
#校验命名参数，建议使用正则
#if [[ ! "${action}" ]]; then logger "" "error"; exit 1; fi
#if [[ ! "${resource}" ]]; then logger "" "error"; exit 1; fi
#if [[ ! "${sequence}" ]]; then logger "" "error"; exit 1; fi
#if [[ ! "${executeProfile}" ]]; then logger "" "error"; exit 1; fi
#if [[ ! "${host}" ]]; then logger "" "error"; exit 1; fi
#if [[ ! "${user}" ]]; then logger "" "error"; exit 1; fi
#倒入配置
targetResourceProfile=${workDir}/manager/default-manager/profile.sh
if [[ -f ${targetResourceProfile} ]]; then source ${targetResourceProfile}; fi
targetResourceProfile=${workDir}/manager/${targetResource}-manager/profile.sh
if [[ -f ${targetResourceProfile} ]]; then source ${targetResourceProfile}; fi
targetResourceProfile=${workDir}/manager/${targetResource}-manager/profile-${executeProfile}.sh
if [[ -f ${targetResourceProfile} ]]; then source ${targetResourceProfile}; fi
#其他参数



#判断必须参数非空


called=${workDir}/node/action/${targetBundleType}.sh
if [ -f ${called} ]
    then bash ${called} ${action} ${targetResource} ${sequence} ${executeProfile} ${host} ${user}
    else
      logger "Unknown bundle type [${targetBundleType}] or script ${called} not found."
      exit 1
fi








if [[ ! $? == 0 ]]; then
    logger "${action^} ${targetResource} on ${host:-local} with ${user:-$(whoami)} when ${executeProfile} ${sequence} failed" "error"
    exit 1
fi
logger "${action^} ${targetResource} on ${host:-local} with ${user:-$(whoami)} when ${executeProfile} ${sequence} succeed"


